﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import flash.display.*;
    import Engine.*;

    public class Vehicle extends NPC {

        private static var m_turnStateToDirection:Array = [0, 8, 7, 9, 3, 10, 4, 11, 2, 12, 5, 13, 1, 14, 6, 15];
        private static var m_directionToTurnState:Array = [0, 12, 8, 4, 6, 10, 14, 2, 1, 3, 5, 7, 9, 11, 13, 15];

        private const TURN_SPEED:Number = 20;

        protected var m_goalTurnState:int;
        protected var m_turnStateProgress:Number;

        public function Vehicle(_arg1:String, _arg2:Boolean, _arg3:Number=-1){
            super(_arg1, _arg2, _arg3);
            this.m_goalTurnState = m_directionToTurnState[m_direction];
            this.m_turnStateProgress = this.m_goalTurnState;
        }
        override public function get isVehicle():Boolean{
            return (true);
        }
        override protected function createFeedbackBubble(_arg1:DisplayObject):Sprite{
            var _local2:DisplayObject = new EmbeddedArt.factoryTruckBubble();
            var _local3:Sprite = new Sprite();
            _local3.addChild(_local2);
            _local3.addChild(_arg1);
            _arg1.x = ((_local3.width - _arg1.width) / 2);
            _arg1.y = ((_local3.height - _arg1.height) / 2);
            return (_local3);
        }
        override public function onUpdate(_arg1:Number):void{
            super.onUpdate(_arg1);
            this.updateTurnAnimation(_arg1);
        }
        public function startTurnAnimation(_arg1:int):void{
            if (m_directionToTurnState[_arg1] != this.m_goalTurnState){
                this.m_goalTurnState = m_directionToTurnState[_arg1];
                this.m_turnStateProgress = m_directionToTurnState[m_direction];
            };
        }
        protected function updateTurnAnimation(_arg1:Number):void{
            if (_arg1 > (1 / this.TURN_SPEED)){
                _arg1 = (1 / this.TURN_SPEED);
            };
            if (Math.floor(this.m_turnStateProgress) == this.m_goalTurnState){
                this.m_turnStateProgress = this.m_goalTurnState;
                return;
            };
            this.m_turnStateProgress = (this.m_turnStateProgress + ((_arg1 * this.TURN_SPEED) * this.getQuickestDirection()));
            this.m_turnStateProgress = MathUtil.wrap(this.m_turnStateProgress, Item.DIRECTION_16_MAX, 0);
            setDirection(m_turnStateToDirection[Math.floor(this.m_turnStateProgress)]);
            setState(getState());
        }
        protected function getQuickestDirection():int{
            var _local1:Number;
            var _local2:Number;
            var _local3:int = ((this.m_goalTurnState > this.m_turnStateProgress)) ? -1 : 1;
            if (_local3 == -1){
                _local1 = (this.m_goalTurnState - this.m_turnStateProgress);
                _local2 = (this.m_turnStateProgress + (Item.DIRECTION_16_MAX - this.m_goalTurnState));
            } else {
                _local1 = (this.m_turnStateProgress - this.m_goalTurnState);
                _local2 = ((Item.DIRECTION_16_MAX - this.m_turnStateProgress) + this.m_goalTurnState);
            };
            return (((_local2 <= _local1)) ? _local3 : (_local3 * -1));
        }

    }
}//package Classes 
